<?php

namespace App\Http\Model;

use Illuminate\Database\Eloquent\Model;
use DB;

class Goods extends Model
{
    protected $table='goods';
    protected $guarded=[];
    public function goodsImage(){
        return $this->hasMany('App\Http\Model\GoodsImage',"goods_id");
    }
    public function clothingAttr(){
        return $this->hasMany('App\Http\Model\ClothingAttr',"goods_id");
    }
    public function clothingAttrLow(){
        return $this->hasMany('App\Http\Model\ClothingAttr','goods_id')->select('price')->orderBy("price", "asc");
    }
    public function clothingAttrHight(){
        return $this->hasMany('App\Http\Model\ClothingAttr','goods_id')->select('price')->orderBy("price", "desc");
    }
    public function clothingAttrPreLow(){
        return $this->hasMany('App\Http\Model\ClothingAttr','goods_id')->select('pre_price')->orderBy("pre_price", "asc");
    }
    public function clothingAttrPreHight(){
        return $this->hasMany('App\Http\Model\ClothingAttr','goods_id')->select('pre_price')->orderBy("pre_price", "desc");
    }
    public function clothingAttrSpec(){
        return $this->hasMany('App\Http\Model\ClothingAttr','goods_id')->distinct()->select('clothing_spec_id','price')->orderBy('price');
    }
    public function clothingDescribe(){
        return $this->belongsTo('App\Http\Model\ClothingDescribe','describe_id');
    }
    public function ordersInfo(){
        return $this->hasMany('App\Http\Model\OrdersInfo','goods_id');
    }
    public function commentAll(){
        return $this->hasMany('App\Http\Model\Comment','goods_id');
    }
    public function commentGood(){
        return $this->hasMany('App\Http\Model\Comment','goods_id')->where("star", ">=" , 3);
    }
    public function ordersInfoSum(){
        return $this->hasMany('App\Http\Model\OrdersInfo','goods_id')->select(DB::raw('sum(num) as sum'));
    }
    public function menu(){
        return $this->belongsTo('App\Http\Model\Menu','menu_id');
    }
}
